﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="LotteryResultManager.aspx.cs"
    Inherits="LotteryVote.LotteryResultManager" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script src="JS/jquery-1.5.1.min.js" type="text/javascript"></script>
    <script src="JS/comm.js" type="text/javascript"></script>
</head>
<body>
    <form id="form1" runat="server" onsubmit="setNum()">
    <div>
        <fieldset>
            <legend>Seach Lottery Result</legend>
            <asp:TextBox ID="txt_date" runat="server"></asp:TextBox>
            <asp:Button ID="btn_GetResult" runat="server" Text="GetResult" OnClick="btn_GetResult_Click" />
        </fieldset>
        <fieldset>
            <legend>Today Lottery Company</legend>
            <asp:RadioButtonList ID="rbl_company" runat="server" RepeatDirection="Horizontal"
                AutoPostBack="true" OnSelectedIndexChanged="rbl_company_SelectedIndexChanged">
            </asp:RadioButtonList>
        </fieldset>
        <div>
            <asp:Label ID="lbl_message" runat="server"></asp:Label>
            <asp:Button ID="btn_getRecord" runat="server" Text="GetTodayRecordByCompany" OnClick="btn_getRecord_Click" />
            <asp:Button ID="btn_canInput" runat="server" Text="CanInputRecord" runat="server"
                OnClick="btn_canInput_Click" />
            <br />
            Num:<asp:TextBox ID="txt_num" runat="server"></asp:TextBox>
            <asp:Button ID="btn_addRecord" runat="server" Text="AddRecord" OnClick="btn_addRecord_Click" />
            <asp:GridView ID="gv_record" runat="server">
            </asp:GridView>
        </div>
        <br />
        <%if (NumLenSupportList != null)
          {%>
        <table id="lotteryNums">
            <% foreach (var support in NumLenSupportList)
               {%>
            <tr>
                <td>
                    <%=support.Length.LenName %>
                </td>
                <%for (int i = 0; i < support.Count; i++)
                  {%>
                <td>
                    <input type="text" maxlength='<%=support.Length.Length %>' style="width: 50px" />
                </td>
                <%} %>
            </tr>
            <%} %>
        </table>
        <%} %>
        <%foreach (var result in this.LotteryResult)
          { %>
        <table border="1" style="float: left">
            <thead>
                <tr>
                    <td>
                        <%=result.Company.Name %>
                    </td>
                </tr>
            </thead>
            <%foreach (var record in result.Records)
              { %>
            <tr>
                <td>
                    <%=record.Value %>
                </td>
            </tr>
            <%} %>
        </table>
        <%} %>
    </div>
    <asp:Button ID="btn_GetJson" runat="server" Text="GetJson" OnClick="btn_GetJson_Click" />
    <asp:Button ID="btn_AddNums" runat="server" Text="AddNums" 
        onclick="btn_AddNums_Click" />
    <a href="javascript:printJson()">GetJSON</a>
    <div id="json">
    </div>
    <script type="text/javascript">
        var printJson = function () {
            $("#json").text(getNumModel());
        }
        var setNum = function () {
            $("#<%=hd_json.ClientID %>").val(getNumModel());
        }
        var getNumModel = function () {
            var numArr = new Array();
            $("#lotteryNums input[type='text']").each(function (i, obj) {
                obj = $(obj);
                var num = obj.val();
                if (isNaN(num))
                    throw new Error(num + "不是数字!");
                numArr.push("{\"PeriodId\":0,\"RecordId\":0,\"Value\":\"" + num + "\"}");
            });
            return "[" + numArr.join() + "]";
        }
    </script>
    <asp:HiddenField ID="hd_json" runat="server" />
    </form>
</body>
</html>
